package com.jhzn.geomap.model;

import lombok.Data;

import java.util.List;

@Data
public class Polygon {
    private Long id;
    private String name;
    private String boundary; // WKT格式的多边形边界
    private String type;
    private List<List<List<Double>>> coordinates;

    // getters and setters

    public List<List<List<Double>>> getCoordinates() {
        return coordinates;
    }

    public void setCoordinates(List<List<List<Double>>> coordinates) {
        this.coordinates = coordinates;
        if (coordinates == null || coordinates.isEmpty()) {
            throw new IllegalArgumentException("Coordinates cannot be null or empty");
        }

        StringBuilder wkt = new StringBuilder("POLYGON((");
        for (List<List<Double>> ring : coordinates) {
            for (List<Double> point : ring) {
                wkt.append(point.get(0)).append(" ").append(point.get(1)).append(", ");
            }
            wkt.setLength(wkt.length() - 2); // Remove last comma and space
            wkt.append("),(");
        }
        wkt.setLength(wkt.length() - 3); // Remove last comma and open parenthesis
        wkt.append("))");
        this.boundary = wkt.toString();
    }

    public void setType(String type) {
        this.type = type;
    }



    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getType() {
        return type;
    }
}